<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    var arr = [2, 9, 4, 6, 1, 3, 8, 7];
    for (var j = 0; j < arr.length - 1; j++) {
        for (var i = j + 1; i < arr.length; i++) {
            if (arr[j] > arr[i]) {
                var small = arr[j];
                arr[j] = arr[i];
                arr[i] = small;
            }
        }
    }
    console.log(arr);
</script>

</html>